package com.kotiln.lgc.lib_base.util

import android.content.Context
import android.content.SharedPreferences

/**
 *@fileName SpUtil
 *@date2021/1/15  11:41
 *@author SpUtil$
 *@describe TODO
 *@desc SharedPreferences 工具
 */
object SpUtil {
    private const val SP_NAME = "config"
    private lateinit var sp: SharedPreferences
    private lateinit var spEditor: SharedPreferences.Editor

    //初始化
    fun initSpUitl(mContext: Context) {
        sp=mContext.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
        spEditor=sp.edit()
        spEditor.apply()
    }

    fun putString(key:String,value:String){
        spEditor.putString(key,value)
        spEditor.commit()
    }

    fun getString(key:String):String?{
        return sp.getString(key,"")
    }

    fun putInt(key:String,value:Int){
        spEditor.putInt(key,value)
        spEditor.commit()
    }

    fun getInt(key:String):Int?{
        return sp.getInt(key,0)
    }

    fun putBoolean(key: String, value: Boolean) {
        spEditor.putBoolean(key, value)
        spEditor.commit()
    }

    fun getBoolean(key: String, defValue: Boolean): Boolean {
        return sp.getBoolean(key, defValue)
    }
}